class Solution {
public:
    ListNode* deleteDuplicates(ListNode* head) {
        if(head == NULL || head->next == NULL)
        {
            return head;
        }
        if(head->val == head->next->val && head->next->next == NULL)
        {
            return NULL;
        }
        ListNode* dummyNode = new ListNode(101, head);
        ListNode* start = dummyNode;
        ListNode* end = head;
        while (end && end->next)
        {
            if (start->next->val == end->next->val)
            {
                while (start->next->val == end->next->val)
                {
                    end = end->next;
                    if(end->next == NULL)
                    break;
                }
                start->next = end->next;
                end = start->next;
                continue;
            }
            start = start->next;
            end = end->next;
        }
        return dummyNode->next;
    }
};